package com.wzl.mixed.service.impl;

import com.wzl.mixed.service.MpAsyncService;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * @Async用法接口实现类
 * @author weizhongli
 * @since 2022-09-12 16:24
 */
@Service
@Slf4j
public class MpAsyncServiceImpl implements MpAsyncService {

//    @Resource
//    private MpAsyncMapper mpAsyncMapper;

    @SneakyThrows
    @Async
    public void doTask1() {
        long t1 = System.currentTimeMillis();
        Thread.sleep(2000);
        long t2 = System.currentTimeMillis();
        log.info(Thread.currentThread().getName()+"---异步线程1 用时 {} ms" , t2-t1);
    }

    @SneakyThrows
    @Async
    public void doTask2() {
        long t1 = System.currentTimeMillis();
        Thread.sleep(3000);
        long t2 = System.currentTimeMillis();
        log.info(Thread.currentThread().getName()+"---异步线程2 用时 {} ms" , t2-t1);
    }


}
